How to make an action button accessible only to a particular user in Microsoft Dynamics NAV

Introduction:

This blog focuses on how to make an action button accessible only to a particular user in Microsoft Dynamics NAV. Below is a scenario

Scenario

The Purchase quote is to be signed off by the CEO then the purchase quote will be posted to create a purchase order. Here an action button is created called Sign off in Purchase Quote.  Here only the CEO will have the authority to sign off.

Pre-requisites:

Microsoft Dynamics NAV 2017

Steps:

1. In the NAV Development Environment, create a Boolean field. e.g CEO in the User Setup table.

2. Add this field to the User setup page and enable this field for the CEO user in the Windows Client

3. Create a button Sign off in the purchase quote also create a boolean field Sign off with property set as Editable : No.

As using extension, we are not supposed to code in the standard objects and Purchase Quote being one of them I’ve created a new codeunit and subscribed it to the action button Sign off.

4. Create a global variable User Setup in the codeunit and refer the below code.

Description of the code: This code checks for the User logged in Microsoft Dynamics NAV and filters the users with CEO boolean field  enabled. If conditions are met then then the Sign off boolean field is enabled and the quote is signed off else message is thrown.

5. In the Windows client/Web Client, browse to Purchase Quote from the search bar and click on Sign off

7. If the User is the authorize user to sign off in this case the CEO then the message is displayed as Purchase Quote is signed off.

Conclusion:

To summarize, create a boolean field in User set up table as CEO and enable the field only for the CEO user. Create an action button and boolean field Sign off where the field is uneditable. Create an event subscriber function for the action button in a codeunit and check for conditions as mentioned in the above code.

Leave a comment